package com.gem.pipeline;

import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;

import java.util.ArrayList;
import java.util.List;

/**
 * Author: Xhy
 * CreateTime: 2022-09-22 11:26
 *
 * 责任链控制器
 */
public class ProcessController {

    private List<BusinessProcess> processList;

    public ProcessController(){
        processList = new ArrayList<>();
    }

    public ProcessController setProcessList(List<BusinessProcess> processList){
        this.processList = processList;
        return this;
    }

    public ProcessContext process(ProcessContext context){
        for (BusinessProcess process : processList) {
            process.process(context);
            if (context.getNeedBreak()){
                break;
            }
        }
        return context;
    }
}
